package cm.day12;


import java.util.concurrent.Executor;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class MyThead3 extends Thread {
    static int sum = 0;
    static Lock lock=new ReentrantLock();

    @Override
    public  void run() {
        while (true) {
lock.lock();
                try {
                    if (sum < 100) {

                            Thread.sleep(100);
                            sum++;
                            System.out.println(getName() + sum + "张票");
                        }else {
                        break;

                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                lock.unlock();
            }


    }
}


public class Test4 {
    public static void main(String[] args) {
        MyThead3 my1 = new MyThead3();
        MyThead3 my2 = new MyThead3();
        MyThead3 my3 = new MyThead3();
        my1.setName("A");
        my2.setName("B");
        my3.setName("C");
        my1.start();
        my2.start();
        my3.start();
    }
}
